package edu.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class LoginServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String userName = req.getParameter("username");
		String password = req.getParameter("password");

		if("admin".equals(userName) && "123".equals(password)){
			//在session中保存用户名
			req.getSession().setAttribute("username",userName);
			req.getRequestDispatcher("HeroList").forward(req, resp);
		}else{
			resp.sendRedirect("login.html");
		}
	}
}
